#include <sdk.h>
#include "globals.h"
#include "manager.h"
#include "sdk_events.h"
#include "ThreadSearchViewManagerLayout.h"
#include "ThreadSearchView.h"

ThreadSearchViewManagerLayout::~ThreadSearchViewManagerLayout() {
}

void ThreadSearchViewManagerLayout::AddViewToManager() {
  if( m_IsManaged == false ) {
    CodeBlocksDockEvent evt( cbEVT_ADD_DOCK_WINDOW );
    evt.name = _T( "ThreadSearch" );
    evt.title = _T( "搜索" );
    evt.pWindow = ( wxWindow* )m_pThreadSearchView;
    evt.desiredSize.Set( 800, 200 );
    evt.floatingSize.Set( 600, 200 );
    evt.minimumSize.Set( 30, 40 );
    evt.stretch = true;
    evt.dockSide = CodeBlocksDockEvent::dsBottom;
    evt.shown = true;
    Manager::Get()->ProcessEvent( evt );
    m_IsManaged = true;
    m_IsShown   = true;
  }
}

void ThreadSearchViewManagerLayout::RemoveViewFromManager() {
  if( m_IsManaged == true ) {
    CodeBlocksDockEvent evt( cbEVT_REMOVE_DOCK_WINDOW );
    evt.pWindow = ( wxWindow* )m_pThreadSearchView;
    evt.shown = false;
    Manager::Get()->ProcessEvent( evt );
    m_IsManaged = false;
    m_IsShown   = false;
  }
}

bool ThreadSearchViewManagerLayout::ShowView( bool show ) {
  if( ( m_IsManaged == false ) || ( show == IsViewShown() ) ) {
    return false;
  }
  CodeBlocksDockEvent evt( show ? cbEVT_SHOW_DOCK_WINDOW : cbEVT_HIDE_DOCK_WINDOW );
  evt.pWindow = ( wxWindow* )m_pThreadSearchView;
  evt.shown = show;
  Manager::Get()->ProcessEvent( evt );
  m_IsShown = show;
  return true;
}

bool ThreadSearchViewManagerLayout::IsViewShown() {
  return m_IsShown && IsWindowReallyShown( ( wxWindow* )m_pThreadSearchView );
}

void ThreadSearchViewManagerLayout::Raise() {
  m_pThreadSearchView->GetParent()->Raise();
}
